<?php
    /**
     * Created by PhpStorm.
     * User: huangzhongwei
     * Date: 2018/11/8
     * Time: 13:32
     */

    namespace app\api\controller;

    use app\api\validate\Ad as AdService;
    use app\api\validate\IDMustBePositiveInt;
    use app\common\model\Ad as AdModel;
    use app\lib\exception\SuccessMessage;

    class Ad extends BaseController
    {
        public function create()
        {
            (new AdService())->goCheck();
            $data = input('post.');
            $ad   = new AdModel();
            $ad->save($data);
            return new SuccessMessage();
        }

        public function edit()
        {
            (new IDMustBePositiveInt())->goCheck();
            (new AdService())->goCheck();
            $data = input('post.');
            $ad   = (new AdModel())->get($data['id']);
            $ad->save($data);
            return new SuccessMessage();
        }

        public function delete()
        {
            (new IDMustBePositiveInt())->goCheck();
            $id = input('post.id');
            AdModel::destroy($id);
            return new SuccessMessage();

        }


        public function get(){
            $ad   = (new AdModel())->select();
            return $ad;
        }

    }